<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: easyui-header('在线用户列表')" />
</head>
<body class="white-bg">
    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-head">
				<div class="easyui-panel">
					<form id="online-form">
						<div class="select-list">
							<ul>
								<li>
									<label>登录名称：</label>
									<input type="text" name="loginName" class="easyui-textbox" data-options="prompt:'请输入登录名称'"/>
								</li>
								<li>
									<label>登录IP：</label>
									<input type="text" name="ipaddr" class="easyui-textbox" data-options="prompt:'请输入登录IP'"/>
								</li>
								<li>
									<a class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="$.easyUIDataGrid.search()" >查询</a>
									<a class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="$.easyUIDataGrid.reset()" >重置</a>
								</li>
							</ul>
						</div>
					</form>
				</div>
			</div>
			<div class="col-sm-12 search-body">
			     <div id="toolbar" role="group">
			     	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-extjs-cancel'" onclick="javascript:batchForceLogout()" shiro:hasPermission="monitor:online:batchForceLogout">强退</a>
		        </div>
			    <table id="dg" class="easyui-datagrid"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: easyui-footer" />
 	<script th:inline="javascript">
		var forceFlag = [[${@permission.hasPermi('monitor:online:forceLogout')}]];
    </script>
	<script th:inline="none">
		var prefix = ctx + "monitor/online";
		$(function(){
			var options = {
	            url: prefix + "/list",
		        exportUrl: prefix + "/export",
	            idField:'sessionId',
	            sortName: "lastAccessTime",
		        sortOrder: "desc",
				columns:[[
					{
						field:'ck',
						checkbox:true,
						width:30
					},
					{
						field:'sessionId',
						title:'会话编号',
						hidden:true,
						width: 20
					},
		          	{
						field:'loginName',
			            title:'登录名称',
		          		align:'center',
		          		width:150
		          	},
		          	{
						field: 'deptName',
			            title: '部门名称',
		          		align: 'center',
		          		width: 150
		          	},
		          	{
						field: 'ipaddr',
			            title: '登录IP',
		          		align: 'center',
		          		width: 100
		          	},
		          	{
						field: 'loginLocation',
			            title: '登录地点',
		          		align: 'center',
		          		width: 150
		          	},
		          	{
						field: 'browser',
			            title: '浏览器',
		          		align: 'center',
		          		width: 80
		          	},
		          	{
						field: 'os',
			            title: '操作系统',
		          		align: 'center',
		          		width: 70
		          	},
		          	{
						field: 'status',
						title: '会话状态',
		          		align:'center',
		          		width: 100,
			            formatter: function(value, row, index) {
			                if (value == 'on_line') {
			                    return '<span class="badge badge-primary">在线</span>';
			                } else if (value == 'off_line') {
			                    return '<span class="badge badge-danger">离线</span>';
			                }
			            }
		          	},
				    {
		          		field:'startTimestamp',
		          		title:'登录时间',
		          		align:'center',
		          		width: 150
		          	},
		          	{
		          		field:'lastAccessTime',
		          		title:'最后访问时间',
		          		align:'center',
		          		width: 150
		          	},
				    {
		          		field:'action',
		          		title:'操作',
		          		align:'center',
		          		width: 100,
			            formatter: function(value, row, index) {
			                var msg = '<a class="btn btn-danger btn-xs ' + forceFlag + '" href="javascript:void(0)" onclick="forceLogout(\'' + row.sessionId + '\')"><i class="fa fa-sign-out"></i>强退</a> ';
			                return msg;
			            }
		          	}
	          	]]
		    };
		    $.easyUIDataGrid.init(options);
		});
		// 单条强退
		function forceLogout(sessionId) {
			$.messager.confirm("确认", "确定要强制选中用户下线吗？", function (isDelete) {
	        	if (isDelete) {
	        		var data = { "ids": sessionId};
			        $.easyUIOperate.post(prefix + "/batchForceLogout", data);
	        	}
	        });
		}
		// 批量强退
		function batchForceLogout() {
			//获取选中行的数据
	        var selectRows = $("#dg").datagrid("getSelections");
	        if (selectRows.length < 1) {
	            $.messager.alert("提示", "请选择要强退的用户！", 'warning');
	            return;
	        }
	        var idsArr = new Array();
	        for(var i=0; i<selectRows.length; i++){
	        	idsArr.push(selectRows[i]['sessionId']);
	        }
	        $.messager.confirm("确认", "确认要强退选中的" + selectRows.length + "条数据吗？", function (isDelete) {
	        	if (isDelete) {
	        		var url = prefix + "/batchForceLogout";
			        var data = { "ids": idsArr.join() };
			        $.easyUIOperate.post(url, data);
	        	}
	        });
		}
	</script>
</body>
</html>